package com.itwn.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itwn.entity.Movie;
import com.itwn.mapper.MovieMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MovieService {
    @Autowired
    MovieMapper movieMapper;
    public List<Movie> findAllMovies(){
        return movieMapper.selectAll();
    }

    public String findMovieTime(Integer movieId) {
        return movieMapper.selectTimeByKey(movieId);
    }

    public PageInfo<Movie> findMoviePage(Integer pageNum, Integer pageSize, String movieName, String movieId) {
        PageHelper.startPage(pageNum, pageSize);
        List<Movie> list = movieMapper.selcetMovieByPage(movieName, movieId);
        return new PageInfo<>(list);
    }

    public int addMovie(Movie movie) {
        return movieMapper.insert(movie);
    }

    public int updateMovie(Movie movie) {
        return movieMapper.updateByPrimaryKey(movie);
    }

    public int removeById(int id) {
        return movieMapper.deleteByPrimaryKey(id);
    }
}
